//
//  SevenPresentTransitionDetailViewController.swift
//  swiftTS
//
//  Created by 航电 on 2020/4/15.
//  Copyright © 2020 航电. All rights reserved.
//

import UIKit

class SevenPresentTransitionDetailViewController: UIViewController {

    public var dataDic:[String:AnyObject]? {
        didSet {
            self.onChangeUIForView();
        }
    }
    public var _imgView:UIImageView!;
    fileprivate var _titleLb:UILabel!;
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "dismiss";
        self.view.backgroundColor = .white;
        // Do any additional setup after loading the view.s
        self.onCreateUIForView();
    }
    

    //MARK:UI
    fileprivate func onCreateUIForView() {
        _imgView = UIImageView(frame: CGRect(x: 10, y: 10, width: screenMainSize.width-20, height: screenMainSize.width-20));
        _imgView.backgroundColor = .clear;
        _imgView.contentMode = .scaleAspectFit;
        _imgView.isUserInteractionEnabled = true;
        _imgView.alpha = 0;
        self.view.addSubview(_imgView);
        let tap = UITapGestureRecognizer(target: self, action: #selector(onTapAction));
        _imgView.addGestureRecognizer(tap);
        
        _titleLb = UILabel(frame: CGRect(x: 0, y: self.view.frame.height-50, width: self.view.frame.width, height: 20));
        _titleLb.backgroundColor = .clear;
        _titleLb.textAlignment = .center;
        _titleLb.textColor = .lightGray;
        _titleLb.font = UIFont.systemFont(ofSize: 16);
        _titleLb.numberOfLines = 0;
        self.view.addSubview(_titleLb);
    }

    //MARK:Actions
    fileprivate func onChangeUIForView() {
        if self.dataDic != nil {
            _imgView.image = UIImage(named: (self.dataDic!["img"] as! String));
            _titleLb.text = (self.dataDic!["title"] as! String);
        }
    }
    
    @objc fileprivate func onTapAction() {
        self.transitioningDelegate = self;
        self.dismiss(animated: true, completion: nil);
    }
}

extension SevenPresentTransitionDetailViewController:UIViewControllerTransitioningDelegate {
    func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        return nil;
    }
    
    func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        return SevenPresentTransition.transitionWithTransitionType(type: .SevenPresentTransitionType_Dismiss);
    }
}
